﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Badger.Vhdl.Types;
using Weazel.Badger.Vhdl.Expressions;
using Weazel.Badger.Vhdl.Statements;

#endregion

namespace Weazel.Badger
{
  public class ClearSignalStatement
  {
    public static SignalAssignmentStatement Get(Vhdl.Signal signal, StatementCollection statements)
    {
      if (signal is RegisterReadSignal || signal is RegisterWriteSignal)
      {        
        VhdlRegister register = signal is RegisterReadSignal ? 
            ((RegisterReadSignal)signal).Register 
          : ((RegisterWriteSignal)signal).Register;

        return new SignalAssignmentStatement(
					register.WriteSignal, 
					new ClearSignalExpression(
						statements,
						register.WriteSignal
					)
				);

      }
      else
      {
        return new SignalAssignmentStatement(
					signal, 
					new ClearSignalExpression(
						statements,
						signal
					)
				);
      }


      /*

      if (signal.Register != null && signal.Register.WriteSignal == signal)
        return new SignalAssignmentStatement(((VhdlRegister)signal).WriteSignal, new ClearSignalExpression(signal));
      else
        return new SignalAssignmentStatement(signal, new ClearSignalExpression(signal));
      */
    }
  }
}